package thread;
//懒汉模式
public class testDemo20 {
    public static void main(String[] args) {
        Lazyton l1=Lazyton.getInstance();
        Lazyton l2=Lazyton.getInstance();
        System.out.println(l2==l1);
    }
}
class Lazyton{
    private static Object lock=new Object();
    private static volatile Lazyton instance=null;
    public static Lazyton getInstance(){//由于线程安全问题，加锁
        if (instance==null){
            synchronized (lock){
                if (instance==null){
                    instance=new Lazyton();
                }
            }
        }
        return instance;
    }
    private Lazyton(){}
}

